/*
********************************************************************************
* Copyright (C) 2021, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : log.cc
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2021-12-17 version v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
                Compile command: make
********************************************************************************
*/
#include <stdio.h>
#include "log.h"

const char LOG_FILE_PATH[] = "debug.log";

static int write_to_file(const char *filename, const char *str)
{
    FILE *fd = NULL;

    fd = fopen(filename, "a+");
    if (fd == NULL) {
        printf("Open %s failed!\n", filename);
        return -1;
    }
    fprintf(fd, "%s", str);

    fclose(fd);
    return 0;
};

CLog* CLog::GetInstance()
{
    static CLog obj;
    return &obj;
}

int CLog::WriteLog(const char *tag, const char *msg)
{
    int ret = 0;

    ret = write_to_file(LOG_FILE_PATH, msg);

    return ret;
}

int CLog::SetLogLevel(int level)
{
    mLevel = level;
    return 0;
}
